package cn.zktr.Personnel.controllers.ouyangpeng;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerIntention;
import cn.zktr.Personnel.model.pojos.PerRetRcd;
//import cn.zktr.Personnel.model.pojos.PerRetItt;
import cn.zktr.Personnel.model.pojos.PerRetWAlt;
import cn.zktr.Personnel.model.service.ouyangpeng.RetIttService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetRcdService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetRseService;
import cn.zktr.Personnel.model.service.ouyangpeng.RetWAltService;

@Controller
public class RetIttController {
	@Autowired
	private RetIttService retittservice;
	@Autowired
	private RetWAltService retwalt;
	@Autowired
	private RetRseService retrse;
	@Autowired
	private RetRcdService retrcdservice;
	//对外招聘
    @RequestMapping("oyp/recruit-duiwai")
    public void demo6(Model model) {
    	recruit(model);
	}

	@RequestMapping("duiwaichaxun")
	@ResponseBody
	public Map<String,Object> selectduiwaisousuo(String d,String w,int page,int rows){
    	System.err.println("框："+w);
    	System.err.println("列："+d);
    	Map<String,Object> map = new HashMap<>();
    	Page<Object> p=PageHelper.startPage(page,rows);
    	List<PerIntention> list=new ArrayList<>();
    	if(w!=null) {
    		list=retittservice.selectduiwaizhi("%"+w+"%");
    		System.err.println("模糊查询"+retittservice.selectduiwaizhi("%"+w+"%"));
    	}else {
//    		if(d!=null) {
//        		if(d!="请选择计划") {
//        			list=retittservice.selectjihuafl("%"+d+"%");
//            		System.err.println("模糊查询"+retittservice.selectjihuafl("%"+d+"%"));
//        		}else {
//        			list=retittservice.selectrsenameAll();
//            		System.err.println("查询所有"+retittservice.selectrsenameAll());
//        		}
//        	}else {
        		list=retittservice.selectrsenameAll();
        		System.err.println("查询所有"+retittservice.selectrsenameAll());
//        	}
    	}
    	map.put("total", p.getTotal());
    	map.put("rows",list);
		return map;
    } 
//	public Map<String,Object> selectjihuafl(String d,int page,int rows){
//    	System.err.println("err."+d);
//    	Map<String,Object> map = new HashMap<>();
//    	Page<Object> p=PageHelper.startPage(page,rows);
//    	List<PerIntention> list=new ArrayList<>();
//    	if(d!=null) {
//    		list=retittservice.selectjihuafl("%"+d+"%");
//    		System.err.println("模糊查询"+retittservice.selectjihuafl("%"+d+"%"));
//    	}else {
//    		list=retittservice.selectrsenameAll();
//    		System.err.println("查询所有"+retittservice.selectrsenameAll());
//    	}
//    	map.put("total", p.getTotal());
//    	map.put("rows",list);
//		return map;
//    } 
	//最终审核表
	@RequestMapping("zuizhong_shenhe")
    @ResponseBody
    public Map<String,Object> shenhezz(int page,int rows){
    	Map<String,Object> map = new HashMap<>();
  		map.put("total",retrcdservice.selectzuizhong().size());
  		Page<Object> p=PageHelper.startPage(page,rows);
  		List<PerRetRcd> findAll=retrcdservice.selectzuizhong();
  		//页内容
  		map.put("rows",findAll);
  		return map;
    }
	//最终审核通过
    @PostMapping("zzshenhe_tongguo")
    @ResponseBody
    private void zuizhongshenhetguo(int zuizhong_shenhe,HttpSession session) {
    	Integer empid = Integer.valueOf(session.getAttribute("id")+"");
    	retrcdservice.zzshenhetg(zuizhong_shenhe,empid);
    }
    //最终审核不通过
    @PostMapping("zzshenhe_butongguo")
    @ResponseBody
    private void zuizhongshenhebutguo(int zuizhong_shenhebtg) {
    	retrcdservice.zzshenhebutg(zuizhong_shenhebtg);
    }
    public void recruit(Model model) {
 			model.addAttribute("deptname", retwalt.selectDept());                 //部门
 			model.addAttribute("empname", retwalt.selectemp());		              //员工
 			model.addAttribute("potname", retwalt.selectpot());                   //职位
 			model.addAttribute("potnames", retrse.selectyuangong());              //职级-职位列表
 			model.addAttribute("fuzerennames", retrse.selectfuzenren());          //负责人
 			model.addAttribute("jnxxname", retwalt.selectjineng());               //技能
 			model.addAttribute("sexname", retrse.selectsex());                    //性别
 			model.addAttribute("jihuanames", retrse.selectjihua());               //招聘计划
 	}

}
